#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "abouthlmdialog.h"
#include "licensedialog.h"
#include "optionsdialog.h"

#include <QDesktopServices>
#include <QUrl>
#include <QtSql/QSqlError>
#include <QtSql/QSqlQuery>
#include <QDebug>
#include <QHBoxLayout>
#include "database.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
    ui->setupUi(this);
    connect(ui->menuAboutQt, SIGNAL(activated()), qApp, SLOT(aboutQt()));
    connect(ui->menuAboutHlm, SIGNAL(activated()), this, SLOT(openAboutHlmDialog()));
    connect(ui->menuLicense, SIGNAL(activated()), this, SLOT(openLicenseDialog()));
    connect(ui->menuOptions, SIGNAL(activated()), this, SLOT(openOptionsDialog()));
    connect(ui->menuOnlineHelp, SIGNAL(activated()), this, SLOT(openOnlineHelp()));
    connect(ui->actionExit, SIGNAL(activated()), this, SLOT(close()));


    Database d;
    if(d.createConnection() == true ) {
        QSqlQuery query("SELECT * FROM KITAP" );
        //qDebug() << query.size() << query.next() << query.lastError();
        while (query.next()) {
            qDebug() << query.value(0).toString() ;
            qDebug() << query.value(1).toString() ;
            qDebug() << query.value(2).toString() ;
        }
    }
    else
        qDebug() << "HATA!";
}

MainWindow::~MainWindow() {
    delete ui;
}

void MainWindow::openAboutHlmDialog() {
    AboutHlmDialog aboutHlm;
    aboutHlm.exec();
}

void MainWindow::openLicenseDialog() {
    LicenseDialog license;
    license.exec();
}

void MainWindow::openOptionsDialog() {
    OptionsDialog od;
    od.exec();
}

void MainWindow::openOnlineHelp() {
    QDesktopServices::openUrl(QUrl("http://www.sourceforge.net"));
}
